import React, { Component } from 'react';
import { Route, withRouter } from 'react-router-dom';
import store from './store';
import { loginStatusActionCreate } from './store/action/action';

import Login from './views/Login/Login';
import Home from './views/Home/Home';
import PartnerAdd from './views/PartnerAdd/PartnerAdd';
import Status from './views/Status/Status';
import Team from './views/Team/Team';
import Forget from './views/Forget/Forget';
import Modification from './views/Modification/Modification';
import Setting from './views/Setting/Setting';
import Task from './views/Task/Task';
import TaskLog from './views/TaskLog/TaskLog';
import Authentication from './views/Authentication/Authentication';
import UserInfo from './views/UserInfo/UserInfo';
import Audit from './views/Audit/Audit';
import Rank from './views/Rank/Rank';
import AuditDetail from './views/AuditDetail/AuditDetail';
import Order from './views/Order/Order';
import WithdrawalLog from './views/WithdrawalLog/WithdrawalLog';

import AnimatedRouter from 'react-animated-router';
import 'react-animated-router/animate.css';

class App extends Component {

  constructor(props) {
    super(props);
    store.subscribe(() => {
      let need = store.getState().navToLogin;
      if (!need) {
        return false;
      }
      store.dispatch(loginStatusActionCreate(false));
      this.props.history.push('/login');
    });
  }

  render() {
    return (
      <AnimatedRouter
      // timeout={300}
      >
        <Route key={1} exact path="/login" component={Login} />
        <Route key={2} exact path="/" component={Home} />
        <Route key={3} exact path="/partner/add" component={PartnerAdd} />
        <Route key={4} exact path="/status" component={Status} />
        <Route key={5} exact path="/team" component={Team} />
        <Route key={6} exact path="/forget" component={Forget} />
        <Route key={7} exact path="/modification" component={Modification} />
        <Route key={8} exact path="/setting" component={Setting} />
        <Route key={9} exact path="/task" component={Task} />
        <Route key={10} exact path="/authentication" component={Authentication} />
        <Route key={11} exact path="/userinfo" component={UserInfo} />
        <Route key={12} exact path="/audit" component={Audit} />
        <Route key={13} exact path="/rank" component={Rank} />
        <Route key={14} exact path="/audit/:id" component={AuditDetail} />
        <Route key={15} exact path="/order" component={Order} />
        <Route key={16} exact path="/withdrawallog" component={WithdrawalLog} />
        <Route key={17} exact path="/task/log" component={TaskLog} />
      </AnimatedRouter>
    );
  }
}

export default withRouter(App)
